"""
HumanMakerPlayer.py

Author: Zach Epolito
Date: 9-22-08

$Id: HumanMakerPlayer.py 325 2008-10-17 02:20:55Z malerba89 $
"""

from HumanMakerInputFrame import HumanMakerInputFrame
from HumanBreakerInputFrame import HumanBreakerInputFrame
from MoveCommand import MoveCommand
from GameView import *

"""represents a human maker
"""
class HumanMakerPlayer:

    """Constructor."""
    def __init__(self, game, host, gui, waitTime):
        self.game = game
        self.host = host
        self.gui = gui
        self.waitTime = waitTime
        
        game.register_observer(self)
        
    """Sets a frame in the GUI to gather input
       Depreciated.
    def strategy(self, contFunctor, GUI, waitTime):
        
        #Requests the GUI to get input from the user
        if self.frame == None:
            self.frame = HumanBreakerInputFrame(GUI.getRootInputView(),
                                                contFunctor, width=300, height=100)
        #self.frame.reset()
        GUI.set_input_view(self.frame)
        self.frame = None"""

    def update(self, subject, param) :
        if subject == self.game:
            if ((param == self.game.NOTIFY_MOVE) or (param == self.game.NOTIFY_UNDO)):
                if self.game.get_last_move().get_player() == "Breaker" : 
                    frame = HumanMakerInputFrame(self.gui.getRootInputView(), self.callback,
                                                  width=300, height=100)
                    self.gui.set_input_view(frame)
            #elif param == Game.NOTIFY_UNDO:

    def callback(self, guess) :
        self.makerMove = MakerMove(guess)

        if self.game.turn == self.game.MAKER_TURN:
            self.moveCommand.execute(self.makerMove)

    def first_callback(self, guess):

        self.makerMove = BreakerMove(guess)
        self.code = self.makerMove
        self.starter()
            
    def setStartingCode(self, startFunctor):
        self.starter = startFunctor
        if self.game.turn == self.game.BREAKER_TURN : 
            frame = HumanBreakerInputFrame(self.gui.getRootInputView(), self.first_callback,
                                           "Set Secret Code:", width=300, height=100)
            self.gui.set_input_view(frame)

    def setWaitTime(self, waitTime):
        self.waitTime = waitTime

        """handle if new game or exit command is executed"""
    def handleCommandExecuted(self, cmd):
        pass

    def setCommands(self, undoCommand, winCommand, moveCommand,
                    exitCommand, newGameCommand):
        self.moveCommand = moveCommand
        
